﻿﻿@model WebApp.Models.RECEIPT
<!-- 弹出窗体form表单 -->
<div id="detailswindow" hidden="hidden" class="easyui-window"
     title="明细数据"
     data-options="modal:true,
                    closed:true,
                    maximized:false,
                    iconCls:'icon-more',
                    footer:'#windowfooter',
                    closeDuration:200,
                    closeAnimation:'slide',
                    openDuration:300,
                    openAnimation:'slide',
                    onBeforeClose:function(){
                      var that = $(this);
                      if(hasmodified()){
                        $.messager.confirm('确认','你确定要放弃保存修改的记录?',function(r){
                        if (r){
                          var opts = that.panel('options');
                          var onBeforeClose = opts.onBeforeClose;
                          opts.onBeforeClose = function(){};
                          that.panel('close');
                          opts.onBeforeClose = onBeforeClose;
                        }
                        });
                        return false;
                      }
                    },
                    onOpen:function(){
                       $(this).window('vcenter');
                       $(this).window('hcenter');
                    },
                    onRestore:function(){
                      $receiptdetailsdg.datagrid('resize');
                    },
                    onMaximize:function(){
                      $receiptdetailsdg.datagrid('resize');
                    }
                    " style="width:1420px;height:520px">
  <!-- begin toolbar -->
  <div class="window-body-toolbar">
    <div class="row">
      <div class="col-sm-8">
        <div class="btn-group btn-group-sm">
          <button onclick="saveitem()" class="btn btn-default">
            <i class="fa fa-floppy-o"></i> @Html.L("Save")
          </button>
        </div>
        <div class="btn-group btn-group-sm" id="deleteitem-btn-group">
          <button onclick="deleteitem()" class="btn btn-danger">
            <i class="fa fa-trash-o"></i> @Html.L("Delete")
          </button>
        </div>
        <div class="btn-group btn-group-sm" style="display:none">
          <button onclick="todo()" class="btn btn-default">
            <i class="fa fa-print"></i> ToDo
          </button>
        </div>
      </div>
      <div class="col-sm-4 text-align-right">
        <div class="btn-group btn-group-sm">
          <button type="button" class="btn   btn-success" onclick="closedetailwindow()">
            <i class="fa fa-chevron-left"></i>
            @Html.L("Close")
          </button>
        </div>
      </div>
    </div>
  </div>
  <!-- end toolbar -->
  <!-- begin window body -->
  <div class="widget-body">
    <form id="receipt_form"
          class="easyui-form form-horizontal padding-10"
          method="post"
          data-options="novalidate:true,
                            onChange: function(target){
                              hasChanged = true;
                             },
                             onLoadSuccess:function(data){
                               hasChanged = false;
                             }">
      @Html.AntiForgeryToken()
      <!--Primary Key-->
      <input type="hidden" id="@Html.IdFor(model => model.ID)"
             name="@Html.NameFor(model => model.ID)"
             value="@Html.ValueFor(model => model.ID)" />
      <!--承运商代码-->
      @Html.HiddenFor(model => model.CARRIERKEY)
      <!--承运商名称-->
      @Html.HiddenFor(model => model.CARRIERNAME)
      <!--合计毛重(KG)-->
      @Html.HiddenFor(model => model.TOTALGROSSWEIGHT)
      <!--合计体积(M)-->
      @Html.HiddenFor(model => model.TOTALVOLUME)
      <!--SUSR4-->
   
      <!--SUSR5-->
      @Html.HiddenFor(model => model.SUSR5)
      <!--SUSR6-->
      @Html.HiddenFor(model => model.SUSR6)
      <!--SUSR7-->
      @Html.HiddenFor(model => model.SUSR7)
      <!--SUSR8-->
      @Html.HiddenFor(model => model.SUSR8)
      <fieldset>
        <!-- begin row -->
        <!--收货单号-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label"><span class="required">@Html.DisplayNameFor(model => model.RECEIPTKEY)</span></label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.RECEIPTKEY)"
                   name="@Html.NameFor(model => model.RECEIPTKEY)"
                   value="@Html.ValueFor(model => model.RECEIPTKEY)"
                   tabindex="0" required
                   class="easyui-textbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.RECEIPTKEY)',
								 required:true,
                                 validType: 'length[0,20]'
                                 " />
          </div>
        </div>
        <!--仓库号-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label"><span class="required">@Html.DisplayNameFor(model => model.WHSEID)</span></label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.WHSEID)"
                   name="@Html.NameFor(model => model.WHSEID)"
                   value="@Html.ValueFor(model => model.WHSEID)"
                   tabindex="1" required
                   class="easyui-textbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.WHSEID)',
								 required:true,
                                 validType: 'length[0,20]'
                                 " />
          </div>
        </div>
        <!--批次号-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label"><span class="required">@Html.DisplayNameFor(model => model.EXTERNRECEIPTKEY)</span></label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.EXTERNRECEIPTKEY)"
                   name="@Html.NameFor(model => model.EXTERNRECEIPTKEY)"
                   value="@Html.ValueFor(model => model.EXTERNRECEIPTKEY)"
                   tabindex="2"
                   class="easyui-textbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.EXTERNRECEIPTKEY)',
								 required:true,
                                 validType: 'length[0,30]'
                                 " />
          </div>
        </div>
        <!--订单编号-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label"><span class="required">@Html.DisplayNameFor(model => model.POKEY)</span></label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.POKEY)"
                   name="@Html.NameFor(model => model.POKEY)"
                   value="@Html.ValueFor(model => model.POKEY)"
                   tabindex="3"
                   class="easyui-textbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.POKEY)',
								                 required:true,
                                 validType: 'length[0,30]'
                                 " />
          </div>
        </div>
        <!--发货单号-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label"><span class="required">@Html.DisplayNameFor(model => model.SUSR4)</span></label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.SUSR4)"
                   name="@Html.NameFor(model => model.SUSR4)"
                   value="@Html.ValueFor(model => model.SUSR4)"
                   tabindex="3"
                   class="easyui-textbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.POKEY)',
								                 required:true,
                                 validType: 'length[0,30]'
                                 " />
          </div>
        </div>
        <!--end row-->
        <!-- begin row -->
        <!--公司名称-->
        <div class="form-group  col-md-3" style="display:none">
          <label class="col-md-3 control-label">@Html.DisplayNameFor(model => model.SUSR2)</label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.SUSR2)"
                   name="@Html.NameFor(model => model.SUSR2)"
                   value="@Html.ValueFor(model => model.SUSR2)"
                   tabindex="4"
                   class="easyui-textbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.SUSR2)',
								 required:false,
                                 validType: 'length[0,80]'
                                 " />
          </div>
        </div>
        <!--工厂名称-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label">@Html.DisplayNameFor(model => model.SUSR3)</label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.SUSR3)"
                   name="@Html.NameFor(model => model.SUSR3)"
                   value="@Html.ValueFor(model => model.SUSR3)"
                   tabindex="5"
                   class="easyui-textbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.SUSR3)',
								 required:false,
                                 validType: 'length[0,80]'
                                 " />
          </div>
        </div>
        <!--货主-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label"><span class="required">@Html.DisplayNameFor(model => model.STORERKEY)</span></label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.STORERKEY)"
                   name="@Html.NameFor(model => model.STORERKEY)"
                   value="@Html.ValueFor(model => model.STORERKEY)"
                   tabindex="6" required
                   class="easyui-textbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.STORERKEY)',
								 required:true,
                                 validType: 'length[0,50]'
                                 " />
          </div>
        </div>
        <!--收货单类型(收货/退货)-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label"><span class="required">@Html.DisplayNameFor(model => model.TYPE)</span></label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.TYPE)"
                   name="@Html.NameFor(model => model.TYPE)"
                   value="@Html.ValueFor(model => model.TYPE)"
                   tabindex="7" required
                   class="easyui-combobox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.TYPE)',
								                 required:true,
                                 data: asntypedatasource,
                                 valueField:'value',
                                 textField:'text'
                                 " />
          </div>
        </div>
        <!--end row-->
        <!-- begin row -->
        <!--状态-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label"><span class="required">@Html.DisplayNameFor(model => model.STATUS)</span></label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.STATUS)"
                   name="@Html.NameFor(model => model.STATUS)"
                   value="@Html.ValueFor(model => model.STATUS)"
                   tabindex="8" required
                   class="easyui-combobox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.STATUS)',
								                 required:true,
                                 readonly:true,
                                 data: asnstatusdatasource,
                                 valueField:'value',
                                 textField:'text'
                                 " />
          </div>
        </div>
        <!--收货单日期-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label"><span class="required">@Html.DisplayNameFor(model => model.RECEIPTDATE)</span></label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.RECEIPTDATE)"
                   name="@Html.NameFor(model => model.RECEIPTDATE)"
                   value="@Html.ValueFor(model => model.RECEIPTDATE)"
                   tabindex="9" required
                   class="easyui-datebox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.RECEIPTDATE)',
								 required:true,
								 formatter:dateformatter" />
          </div>
        </div>
        <!--到货通知日期-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label"><span class="required">@Html.DisplayNameFor(model => model.ADVICEDATE)</span></label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.ADVICEDATE)"
                   name="@Html.NameFor(model => model.ADVICEDATE)"
                   value="@Html.ValueFor(model => model.ADVICEDATE)"
                   tabindex="10" required
                   class="easyui-datebox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.ADVICEDATE)',
								 required:true,
								 formatter:dateformatter" />
          </div>
        </div>
        <!--预计收货日期-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label">@Html.DisplayNameFor(model => model.EXPECTEDRECEIPTDATE)</label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.EXPECTEDRECEIPTDATE)"
                   name="@Html.NameFor(model => model.EXPECTEDRECEIPTDATE)"
                   value="@Html.ValueFor(model => model.EXPECTEDRECEIPTDATE)"
                   tabindex="11"
                   class="easyui-datebox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.EXPECTEDRECEIPTDATE)',
								 required:false,
								 formatter:dateformatter" />
          </div>
        </div>
        <!--end row-->
        <!-- begin row -->
        <!--实际到货日期-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label">@Html.DisplayNameFor(model => model.ARRIVALDATETIME)</label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.ARRIVALDATETIME)"
                   name="@Html.NameFor(model => model.ARRIVALDATETIME)"
                   value="@Html.ValueFor(model => model.ARRIVALDATETIME)"
                   tabindex="12"
                   class="easyui-datetimebox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.ARRIVALDATETIME)',
								 required:false,
								 formatter:datetimeformatter" />
          </div>
        </div>
        <!--结案日期-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label">@Html.DisplayNameFor(model => model.CLOSEDDATE)</label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.CLOSEDDATE)"
                   name="@Html.NameFor(model => model.CLOSEDDATE)"
                   value="@Html.ValueFor(model => model.CLOSEDDATE)"
                   tabindex="13"
                   class="easyui-datebox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.CLOSEDDATE)',
								 required:false,
								 formatter:dateformatter" />
          </div>
        </div>
        <!--供应商代码-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label">@Html.DisplayNameFor(model => model.SUPPLIERCODE)</label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.SUPPLIERCODE)"
                   name="@Html.NameFor(model => model.SUPPLIERCODE)"
                   value="@Html.ValueFor(model => model.SUPPLIERCODE)"
                   tabindex="14"
                   class="easyui-combogrid"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.SUPPLIERCODE)',
								                 required:true,
                                 validType: 'length[0,20]',
                                  panelHeight: 'auto',
                   mode: 'remote',
        url: '',
        method: 'get',
        idField: 'SUPPLIERCODE',
        panelWidth: 350,
        pagination: true,
        pageSize:10,
                   delay: 600,
        textField: 'SUPPLIERCODE',
        columns: [[
          { field: 'SUPPLIERCODE', title: '供应商代码', width: 110 },
          { field: 'SUPPLIERNAME', title: '供应商名称', width: 220 }
        ]],
        onClickRow: function (index,row) {
                   $('#SUPPLIERNAME').textbox('setValue',row.SUPPLIERNAME)
           
        }
                                 " />
          </div>
        </div>
        <!--供应商名称-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label">@Html.DisplayNameFor(model => model.SUPPLIERNAME)</label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.SUPPLIERNAME)"
                   name="@Html.NameFor(model => model.SUPPLIERNAME)"
                   value="@Html.ValueFor(model => model.SUPPLIERNAME)"
                   tabindex="15"
                   class="easyui-textbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.SUPPLIERNAME)',
								 required:false,
                   readonly:true,
                                 validType: 'length[0,80]'
                                 " />
          </div>
        </div>
        <!--end row-->
        <!-- begin row -->
        <!--合计数量-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label"><span class="required">@Html.DisplayNameFor(model => model.TOTALQTY)</span></label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.TOTALQTY)"
                   name="@Html.NameFor(model => model.TOTALQTY)"
                   value="@Html.ValueFor(model => model.TOTALQTY)"
                   tabindex="16"
                   class="easyui-numberbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.TOTALQTY)',
								                 required:true,
                                 readonly:true,
                                 precision:2

                                 " />

          </div>
        </div>
        <!--合计未收数量-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label"><span class="required">@Html.DisplayNameFor(model => model.OPENQTY)</span></label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.OPENQTY)"
                   name="@Html.NameFor(model => model.OPENQTY)"
                   value="@Html.ValueFor(model => model.OPENQTY)"
                   tabindex="17"
                   class="easyui-numberbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.OPENQTY)',
								                 required:true,
                                 readonly:true,
                                 precision:2

                                 " />

          </div>
        </div>
        <!--合计件数-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label">@Html.DisplayNameFor(model => model.TOTALPACKAGE)</label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.TOTALPACKAGE)"
                   name="@Html.NameFor(model => model.TOTALPACKAGE)"
                   value="@Html.ValueFor(model => model.TOTALPACKAGE)"
                   tabindex="18"
                   class="easyui-numberbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.TOTALPACKAGE)',
								                 required:false,
                                 readonly:true,
                                 precision:2

                                 " />

          </div>
        </div>
        <!--备注-->
        <!--end row-->
        <!-- begin row -->
        <!--上传用户-->
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label">@Html.DisplayNameFor(model => model.SUSR1)</label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.SUSR1)"
                   name="@Html.NameFor(model => model.SUSR1)"
                   value="@Html.ValueFor(model => model.SUSR1)"
                   tabindex="20"
                   class="easyui-textbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.SUSR1)',
								 required:false,
                                 validType: 'length[0,50]'
                                 " />
          </div>
        </div>
        <div class="form-group  col-md-3">
          <label class="col-md-3 control-label">@Html.DisplayNameFor(model => model.NOTES)</label>
          <div class="col-md-9">
            <input id="@Html.IdFor(model => model.NOTES)"
                   name="@Html.NameFor(model => model.NOTES)"
                   value="@Html.ValueFor(model => model.NOTES)"
                   tabindex="19"
                   class="easyui-textbox"
                   style="width:100%"
                   type="text"
                   data-options="prompt:'@Html.DisplayNameFor(model => model.NOTES)',
								                 required:false,
                                 validType: 'length[0,100]'
                                 " />
          </div>
        </div>
        <!--end row-->
      </fieldset>
    </form>

    <!--end form表单界面-->
    <!--========================================================================================-->
    <!-- begin details row -->
    <div class="row" style="margin:0px;">
      <div class="col-md-12">
        <!-- details tabs -->
        <div class="tabs-container">
          <!-- Nav tabs -->
          <ul class="nav nav-tabs bordered">
            <li class="active"><a data-toggle="tab" href="#tab-receiptdetails"> 收货单明细 </a></li>

          </ul>
          <!-- Tab panes -->
          <div class="tab-content">
            <div id="tab-receiptdetails" class="tab-pane active">
              <div class="panel-body-toolbar">
                <div class="row">
                  <div class="col-sm-8  ">
                    <div class="btn-group btn-group-sm">
                      <button onclick="receiptdetails_append()" class="btn btn-default"> <i class="fa fa-plus"></i> @Html.L("Add") </button>
                    </div>
                    <div class="btn-group btn-group-sm">
                      <button onclick="receiptdetails_removeit()" class="btn  btn-default"> <i class="fa fa-trash-o"></i> @Html.L("Delete") </button>
                    </div>
                    <div class="btn-group btn-group-sm">
                      <button onclick="receiptdetails_accept()" class="btn  btn-default"> <i class="fa fa-floppy-o"></i> @Html.L("Save") </button>
                    </div>
                    <div class="btn-group btn-group-sm">
                      <button onclick="receiptdetails_reload()" class="btn btn-default"> <i class="fa fa-refresh"></i> @Html.L("Refresh") </button>
                    </div>
                    <div class="btn-group btn-group-sm">
                      <button onclick="receiptdetails_reject()" class="btn  btn-default"> <i class="fa fa-window-close-o"></i> @Html.L("Cancel") </button>
                    </div>
                  </div>
                </div>
              </div>
              <div class="table-responsive">
                <table id="receiptdetails_datagrid"></table>

              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!--end details tabs -->
  </div>
  <!--end window body -->
</div>
<div id="windowfooter" style="padding:5px;">&nbsp;</div>
<!-- 弹出窗体form表单 -->
<!-- 弹出编辑对话框 -->
<!-- receiptdetail datagrid  javascript block -->
@Html.Partial("_RECEIPTDETAILEditForm", new WebApp.Models.RECEIPTDETAIL())

<!--begin popup detailview javascript block -->
<script type="text/javascript">
  //判断新增编辑状态
  var MODELSTATE = 'Added';
  var receiptid = null;
  var hasChanged = false;
  function opendetailwindow(data, state) {
    MODELSTATE = state;
    initdetailview();
    receiptid = (data.ID || 0);
    $("#detailswindow").window("open");
    $('#receipt_form').form('reset');
    $('#receipt_form').form('load', data);
    var url = '/RECEIPTDETAILs/GetDataByRECEIPTIDAsync?receiptid=' + receiptid;
    $receiptdetailsdg.datagrid('load', url);
    $receiptdetailsdg.datagrid('resize');
    $('#SUPPLIERCODE').combogrid('grid').datagrid('load', '/SUPPLIERs/GetComboData');
    var pager = $('#SUPPLIERCODE').combogrid('grid').datagrid('getPager');
    pager.pagination({
      layout: ['first', 'prev', 'links', 'next', 'last']
    });

    if (MODELSTATE != 'Added' && data.STATUS != '100') {
      $('#receipt_form').form('disable');
      $('#receiptdetail_form').form('disable');

      $('.window-body-toolbar *').prop('disabled', true);
      $('.panel-body-toolbar *').prop('disabled', true);
    } else {
      $('#receipt_form').form('enable');
      $('#receiptdetail_form').form('enable');

      $('.window-body-toolbar *').prop('disabled', false);
      $('.panel-body-toolbar *').prop('disabled', false);
    }

  }
  //删除当前记录
  function deleteitem() {
    if ($('#STATUS', '#receipt_form').combobox('getValue')!='100') {
      $.messager.alert('提示', '只有<span class="required"> [待入库] </span>状态才允许删除!', 'info');
      return;
    }
    $.messager.confirm('确认', '你确定要删除该记录?', result => {
      if (result) {
        const url = `/RECEIPTs/DeleteAsync/${receiptid}`;
        $.get(url).done(res => {
          if (res.success) {
            toastr.success("删除成功");
            $dg.datagrid('reload');
            $("#detailswindow").window("close");
          } else {
            $.messager.alert("错误", res.err, "error");
          }
        });
      }
    });
  }
  //async 保存数据
  async function saveitem() {
    var $editform = $('#receipt_form');
    if ($editform.form('enableValidation').form('validate')) {
      let receipt = $editform.serializeJSON();
      //获取明细表数据

      const receiptdetails_res = await receiptdetails_accept();
      if (!receiptdetails_res.success) {
        return false;
      } else {
        if (receiptdetails_res.changed) {
          receipt.RECEIPTDETAILS = receiptdetails_res.changed;
        }
      }

      let url = '/RECEIPTs/EditAsync';
      //判断是新增或是修改方法
      if (MODELSTATE === 'Added') {
        url = '/RECEIPTs/CreateAsync';
      }
      var token = $('input[name="__RequestVerificationToken"]', $editform).val();
      $.ajax({
        type: "POST",
        url: url,
        data: {
          __RequestVerificationToken: token,
          receipt: receipt
        },
        dataType: 'json',
        contentType: 'application/x-www-form-urlencoded; charset=utf-8'
      })
        .done(response => {
          if (response.success) {
            hasChanged = false;
            $editform.form('disableValidation');
            $dg.datagrid('reload');
            $('#detailswindow').window("close");
            toastr.success("保存成功");
          } else {
            $.messager.alert("错误", response.err, "error");
          }
        })
        .fail((jqXHR, textStatus, errorThrown) => {
          $.messager.alert('异常', `${jqXHR.status}: ${jqXHR.statusText} `, 'error');
        });
    }
  }
  //关闭窗口
  function closedetailwindow() {
    $('#detailswindow').window('close');
  }
  //todo
  function todo() {
    console.log('todo.....');
  }
  //判断是否有没有保存的记录
  function hasmodified() {
    if (hasChanged) return hasChanged;
    if (!receiptdetails_endEditing()) {
      return true;
    }
    const receiptdetails = $receiptdetailsdg.datagrid("getChanges");
    if (MODELSTATE == 'Modified' && receiptdetails.length > 0) {
      return true;
    }
    return false;

  }


  function initdetailview() {
    //判断是否显示功能按钮
    if (MODELSTATE === 'Added') {
      $('#deleteitem-btn-group').hide();
    } else {
      $('#deleteitem-btn-group').show();
    }
    $('a[data-toggle="tab"]').on('shown.bs.tab', e => {
      const target = $(e.target).attr("href");
      if (target === "#tab-receiptdetails")
        $receiptdetailsdg.datagrid("resize");
    });

    //回车光标移动到下个输入控件
    //如果是枚举类型需要把numberbox改成combobox
    //合计数量
    $('#TOTALQTY').numberbox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //如果是枚举类型需要把numberbox改成combobox
    //合计未收数量
    $('#OPENQTY').numberbox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //如果是枚举类型需要把numberbox改成combobox
    //合计件数
    $('#TOTALPACKAGE').numberbox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //如果是枚举类型需要把numberbox改成combobox
    //合计毛重(KG)
    //$('#TOTALGROSSWEIGHT').numberbox('textbox').bind('keydown', function (e) {
    //  if (e.keyCode == 13) {
    //    $(e.target).emulateTab();
    //  }
    //});
    //如果是枚举类型需要把numberbox改成combobox
    //合计体积(M)
    //$('#TOTALVOLUME').numberbox('textbox').bind('keydown', function (e) {
    //  if (e.keyCode == 13) {
    //    $(e.target).emulateTab();
    //  }
    //});
    //如果是枚举类型需要把numberbox改成combobox
    //SUSR6
    //$('#SUSR6').numberbox('textbox').bind('keydown', function (e) {
    //  if (e.keyCode == 13) {
    //    $(e.target).emulateTab();
    //  }
    //});
    //如果是枚举类型需要把numberbox改成combobox
    //SUSR7
    //$('#SUSR7').numberbox('textbox').bind('keydown', function (e) {
    //  if (e.keyCode == 13) {
    //    $(e.target).emulateTab();
    //  }
    //});
    //日期类型 收货单日期
    $('#RECEIPTDATE').datebox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //日期类型 到货通知日期
    $('#ADVICEDATE').datebox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //日期类型 预计收货日期
    $('#EXPECTEDRECEIPTDATE').datebox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //日期类型 实际到货日期
    $('#ARRIVALDATETIME').datebox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //日期类型 结案日期
    $('#CLOSEDDATE').datebox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //日期类型 SUSR8
    //$('#SUSR8').datebox('textbox').bind('keydown', function (e) {
    //  if (e.keyCode == 13) {
    //    $(e.target).emulateTab();
    //  }
    //});
  }
</script>

